package top.wnma.crud.service.impl;

import java.io.Serializable;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.wnma.crud.dao.StaffDao;
import top.wnma.crud.pojo.Staff;
import top.wnma.crud.service.IStaffService;

@Service
@Transactional
public class StaffServiceImpl implements IStaffService {

	@Autowired
	private StaffDao staffDao;
	
	public void setStaffDao(StaffDao staffDao) {
		this.staffDao = staffDao;
	}

	public void save(Staff entity) {
		staffDao.save(entity);
	}

	public void delete(Staff entity) {
		staffDao.delete(entity);
	}

	public void update(Staff entity) {
		staffDao.update(entity);
	}

	public void saveOrUpdate(Staff staff) {
		if(staff.getSdate()==null) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			
			staff.setSdate(new Date(1999-05-02));//new Date(2012, 07, 14)
		}
		if(staff.getSstatus()==null || staff.getSstatus().equals("")) {
			staff.setSstatus("1");
		}
		if (staff.getSsex()==null || staff.getSsex().equals("")) {
			staff.setSsex("男");
		}
		
		staffDao.saveOrUpdate(staff);
	}

	public Staff findById(Serializable id) {
		
		return staffDao.findById(id);
	}

	public List<Staff> findAll() {
		return staffDao.findAll();
	}

}
